import Vue from 'vue'
import Router from 'vue-router'
import Utils from '@/utils/index.js' // 自定义公共js,包含全局变量公共方法

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  { path: '*',
    redirect: '/home',
    hidden: true
  },
  // { path: '*',
  //   redirect: '/404',
  //   hidden: true
  // },

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/home',
    component: Layout,
    redirect: '/home/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' },
      hidden: true
    }]
  }

  // {
  //   path: '/system',
  //   component: () => import('@/layout'),
  //   redirect: '/system/menuManage',
  //   name: '系统管理',
  //   meta: { title: '系统管理', icon: 'el-icon-setting' },
  //   children: [
  //     {
  //       path: 'menuManage',
  //       name: '菜单管理',
  //       component: () => import('@/views/system/MenuManage.vue'),
  //       meta: { title: '菜单管理' }
  //     },
  //     {
  //       path: 'department',
  //       name: '部门管理',
  //       component: () => import('@/views/system/DepartmentManage.vue'),
  //       meta: { title: '部门管理' }
  //     }
  //   ]
  // },

  // {
  //   path: '/userRole',
  //   component: () => import('@/layout'),
  //   redirect: '/userRole/UserManage',
  //   name: '用户角色',
  //   meta: { title: '用户角色', icon: 'el-icon-user-solid' },
  //   children: [
  //     {
  //       path: 'userManage',
  //       name: '用户管理',
  //       component: () => import('@/views/userRole/UserManage.vue'),
  //       meta: { title: '用户管理' }
  //     },
  //     {
  //       path: 'roleManage',
  //       name: '角色管理',
  //       component: () => import('@/views/userRole/RoleManage.vue'),
  //       meta: { title: '角色管理' }
  //     }
  //   ]
  // }

]

// if (sessionStorage.getItem('subsystemMenuList')) {
//   const subsystemMenuList = JSON.parse(sessionStorage.getItem('subsystemMenuList'))
//   const dnyRoutes = Utils.dnyCreateRouter(subsystemMenuList)

//   dnyRoutes.push(
//     { path: '*',
//       redirect: '/404',
//       hidden: true
//     },
//   )

//   constantRoutes = constantRoutes.concat(dnyRoutes)
// }

const createRouter = (rout) => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: rout
})

const router = createRouter(constantRoutes)

export function resetRouter() {
  const newRouter = createRouter(null)
  router.matcher = newRouter.matcher // reset router
}

export default router
